package com.ruoyi.web.controller.gwc;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gwc.domain.TEtcManagement;
import com.ruoyi.gwc.service.ITEtcManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ETC管理Controller
 * 
 * @author wp
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/gwc/etcManagement")
public class TEtcManagementController extends BaseController
{
    @Autowired
    private ITEtcManagementService tEtcManagementService;

    /**
     * 查询ETC管理列表
     */
    @ApiOperation("查询ETC管理列表")
    @GetMapping("/list")
    public TableDataInfo list(TEtcManagement tEtcManagement)
    {
        startPage();
        LoginUser loginUser = getLoginUser();
        if (!loginUser.getUser().isAdmin() && !StringUtils.isNotNull((tEtcManagement.getCompanyId()))) {
            tEtcManagement.setCompanyId(loginUser.getUser().getDeptId());
        }
        List<TEtcManagement> list = tEtcManagementService.selectTEtcManagementList(tEtcManagement);
        for (TEtcManagement etcManagement : list ){
            if(ObjectUtils.isNotEmpty(etcManagement.getAmount())) {
                etcManagement.setAmountStr(etcManagement.getAmount().toString());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出ETC管理列表
     */
    @Log(title = "ETC管理", businessType = BusinessType.EXPORT)
    @ApiOperation("导出ETC管理列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TEtcManagement tEtcManagement)
    {
        List<TEtcManagement> list = tEtcManagementService.selectTEtcManagementList(tEtcManagement);
        ExcelUtil<TEtcManagement> util = new ExcelUtil<TEtcManagement>(TEtcManagement.class);
        util.hideColumn("remark");
        util.exportExcel(response, list, "ETC管理数据");
    }

    /**
     * 获取ETC管理详细信息
     */
    @ApiOperation("获取ETC管理详细信息")
    @GetMapping(value = "/{ectId}")
    public AjaxResult getInfo(@PathVariable("ectId") Long ectId)
    {
        return success(tEtcManagementService.selectTEtcManagementByEctId(ectId));
    }

    /**
     * 新增ETC管理
     */
    @ApiOperation("新增ETC管理")
    @Log(title = "ETC管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TEtcManagement tEtcManagement)
    {
        tEtcManagement.setAmount(new BigDecimal(tEtcManagement.getAmountStr()));
        return toAjax(tEtcManagementService.insertTEtcManagement(tEtcManagement));
    }

    /**
     * 修改ETC管理
     */
    @ApiOperation("修改ETC管理")
    @Log(title = "ETC管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TEtcManagement tEtcManagement)
    {
        tEtcManagement.setAmount(new BigDecimal(tEtcManagement.getAmountStr()));
        return toAjax(tEtcManagementService.updateTEtcManagement(tEtcManagement));
    }

    /**
     * 删除ETC管理
     */
    @ApiOperation("删除ETC管理")
    @Log(title = "ETC管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ectIds}")
    public AjaxResult remove(@PathVariable Long[] ectIds)
    {
        return toAjax(tEtcManagementService.deleteTEtcManagementByEctIds(ectIds));
    }
}
